home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000030_icon-group-sender _Sun Jan 23 10:35:09 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  4KB

  1. Received: by cheltenham.cs.arizona.edu; Sun, 30 Jan 1994 20:22:17 MST
  2. Date: 23 Jan 94 10:35:09 GMT
  3. From: noc.near.net!news.delphi.com!usenet@uunet.uu.net  (Will Mengarini)
  4. Organization: Delphi Internet
  5. Subject: MS-DOS drive/dir query routines
  6. Message-Id: <940123.20109.MENGARINI@delphi.com>
  7. Sender: icon-group-request@cs.arizona.edu
  8. To: icon-group@cs.arizona.edu
  9. Status: RO
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. I suggest the Icon Project incorporate this in BIPL.
  13.  
  14. -------------------------------<CUT HERE (duh)>------------------------------
  15. ############################################################################
  16. #
  17. #  File:     drivedir.icn
  18. #
  19. #  Subject:  Procedures to inquire MS-DOS working dirs & current drive
  20. #
  21. #  Author:   Will Mengarini
  22. #
  23. #  Date:     Sa 18 Sep 93
  24. #
  25. ############################################################################
  26. #
  27. #  Requires:  MS-DOS, DR-DOS, or compatible system
  28. #
  29. ############################################################################
  30. #
  31. #  Every disk drive on a MS-DOS system has a "working directory", which is
  32. #  the directory referred to by any references to that drive that don't begin
  33. #  with a backslash (& so are either direct references to that working
  34. #  directory, or paths relative to it). There is also 1 "current drive", &
  35. #  its working directory is called the "current working directory". Any paths
  36. #  that don't explicitly specify a drive refer to the current drive. For
  37. #  example, "name.ext" refers to the current drive's working directory, aka
  38. #  the current working directory; "\name.ext" refers to the current drive's
  39. #  root directory; & "d:name.ext" refers to the working directory on d:.
  40. #
  41. #  It's reasonable to want to inquire any of these values. The CD command
  42. #  displays both, in the form of a complete path to the current working
  43. #  directory. However, passing such a path to either CD or the Icon function
  44. #  chdir() doesn't change to that dir on that drive; it changes that drive's
  45. #  working directory to the specified path without changing the current
  46. #  drive. The command to change the current drive is the system() function
  47. #  of a command consisting of just the drive letter followed by ":".
  48. #
  49. #  This affects the design of inquiry functions. They could be implemented
  50. #  with system(  "CD >" || ( name := tempname() )  ) & read(open(name)), but
  51. #  because this requires a slow disk access (which could fail on a full disk)
  52. #  it's unacceptable to need to do that *twice*, once for the drive & again
  53. #  for the dir; so if that strategy were used, it'd be necessary to return a
  54. #  structure containing the current drive & the working directory. That
  55. #  structure, whether table, list, or string, would then need to be either
  56. #  indexed or string-scanned to get the individual values, making the code
  57. #  cumbersome & obscure. It's much better to have 2 separate inquiry
  58. #  functions, 1 for each value; but for this to be acceptably efficient, it's
  59. #  necessary to forgo the disk access & implement the functions with
  60. #  interrupts.
  61. #
  62. #  getdrive() returns the current drive as a lowercase string with the ":".
  63. #  getwd("g") and getwd("g:") return the working directory on drive g:, or
  64. #  fail if g: doesn't exist. getwd() returns the current working directory.
  65. #  getwd(...) always returns lowercase. It prepends the relevant drive letter
  66. #  with its colon; that's harmless in a chdir(), & useful in an open().
  67. #
  68. ############################################################################
  69.  
  70. procedure getdrive()
  71.    return &lcase[iand( Int86([33,16r1900,0,0,0,0,0,0,0])[2], 255 )+1] || ":"
  72. end
  73.  
  74. procedure getwd(drive)
  75.    A := GetSpace(64) | stop( "getwd(): GetSpace() failed." )
  76.    dx := ("36r" || !\drive) - 9 | 0
  77.    si := iand( A, 16rffff ); ds := ishift( A, -16 )
  78.    cf := !Int86([33,16r4700,0,0,dx,si,0,0,ds]) % 2
  79.    Peek( A , 64 ) ? path := tab(many(~'\0')) | ""
  80.    FreeSpace(A)
  81.    cf = 0 | fail
  82.    return (   map(!\drive) || ":"   |   getdrive()   ) || "\\" || map(path)
  83. end
  84. -------------------------------<CUT HERE (duh)>------------------------------
  85.